package com.weasing.res.utils;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;

/**
 * 包装类 分页属性
 * @author long
 *
 */
public class PageBean {
	private int currentPage = 1;// 当前页
	private int pageSize = 10;// 每页显示的记录数
	private DetachedCriteria detachedCriteria; //离线查询对象
	private int total ;//总记录数
	private int totalPage;// 总页数
	private List rows;//当前页需要展示的数据集合
	
	private int startRow; // 起始行 (当前页-1)*每页显示条数
	private int firstPage = 1; // 首页
	private int lastPage; // 尾页
	private int prePage; // 上一页
	private int nextPage; // 下一页
	private int beginNav; // 起始导航
	private int endNav; // 起始导航
	
	public PageBean() {
	}

	// 带参数的构造器
	public PageBean(int currentPage, int total) {
		this.currentPage = currentPage;
		this.total = total;

		this.startRow = (currentPage - 1) * this.pageSize;
		this.totalPage = (total + this.pageSize - 1) / this.pageSize;
		this.lastPage = this.totalPage;
		
		this.prePage = currentPage == this.firstPage ? this.firstPage
				: currentPage - 1;
		this.nextPage = currentPage == this.lastPage ? this.lastPage
				: currentPage + 1;
		
		// 10页一下的分页
		if (this.totalPage < 10) {
			this.beginNav = this.firstPage;
			this.endNav = this.lastPage;
		}else{
			// 10页以上的分页
			if (currentPage <= 6) {
				this.beginNav = 1;
				this.endNav = 10;
			} else if (currentPage + 4 >= this.lastPage) {
				this.beginNav = this.lastPage - 9;
				this.endNav = this.lastPage;
			} else {
				this.beginNav = currentPage - 5;
				this.endNav = currentPage + 4;
			}

		}

	}

	public int getStartRow() {
		return startRow;
	}

	public void setStartRow(int startRow) {
		this.startRow = startRow;
	}

	public int getFirstPage() {
		return firstPage;
	}

	public void setFirstPage(int firstPage) {
		this.firstPage = firstPage;
	}

	public int getLastPage() {
		return lastPage;
	}

	public void setLastPage(int lastPage) {
		this.lastPage = lastPage;
	}

	public int getPrePage() {
		return prePage;
	}

	public void setPrePage(int prePage) {
		this.prePage = prePage;
	}

	public int getNextPage() {
		return nextPage;
	}

	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}

	public int getBeginNav() {
		return beginNav;
	}

	public void setBeginNav(int beginNav) {
		this.beginNav = beginNav;
	}

	public int getEndNav() {
		return endNav;
	}

	public void setEndNav(int endNav) {
		this.endNav = endNav;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	public DetachedCriteria getDetachedCriteria() {
		return detachedCriteria;
	}
	public void setDetachedCriteria(DetachedCriteria detachedCriteria) {
		this.detachedCriteria = detachedCriteria;
	}
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getTotal() {
		return total;
	}
	public void setTotal(int total) {
		this.total = total;
	}
	public List getRows() {
		return rows;
	}
	public void setRows(List rows) {
		this.rows = rows;
	}
	
	
}
